// pages/money/money.js
const {money} =require('../../util/api')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    winshow:false,
    moneytype:'请选择筛选类型',
    balance:"",
    notBalance:"",
    userId:"",
    list:[],
    startdate:'',
    enddate:'',
   
  },
  bindstrttime(e){
    console.log(e)
    this.setData({
      startdate:e.detail.value
    })
  },
  bindendtime(e){
    console.log(e)
    this.setData({
      enddate:e.detail.value
    })
  },

  selecttype(e){
   
     this.setData({
       winshow:false,
       moneytype:e.currentTarget.dataset.type
     })
  },
  openwinshow(){
    this.setData({
      winshow:true
    })
  },
  close(){
    this.setData({
      winshow:false
    })
  },
  selectdate(){
      if(this.data.startdate!=''){
        if(this.data.enddate==''){
        wx.showToast({
          title: '请选择结束时间',
          icon: 'none',
          duration: 2000
        })
        return
      }
    }
    if(this.data.enddate!=''){
      if(this.data.startdate==''){
      wx.showToast({
        title: '请选择开始时间',
        icon: 'none',
        duration: 2000
      })
        return
      }
    }
    let p={};
    if(this.data.moneytype!='请选择筛选类型'){
      p={
        status:this.data.moneytype,
        userId:this.data.userId,
        beginTime:this.data.startdate,
        endTime:this.data.enddate,
      }
    }else{
      p={
        beginTime:this.data.startdate,
        endTime:this.data.enddate,
        userId:this.data.userId
      }
    } 
console.log(p)
    money(p).then(res=>{
      console.log(res)
      if(res.code==200){
        this.setData({
          list:res.data.details
        })
      }else{
        wx.showToast({
          title: res.msg,
          icon: 'none',
          duration: 2000
        })
      }
    })
  },
  resetting(){
    this.setData({
      moneytype:'请选择筛选类型',
      startdate:'',
      enddate:''
    })
  },
  tixian(){
    wx.navigateTo({
      url: '/pages/tixian/tixian?notBalance='+this.data.notBalance,
    })
    console.log("提现")
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
    userId:wx.getStorageSync('userId')
    }
    )
    let p={
      userId:this.data.userId
    }
    money(p).then(res=>{
      this.setData({
        balance:res.data.balance ,
        list:res.data.details,
        notBalance:res.data.notBalance,
        shenhe:res.data.shenhejine
      })
      console.log(res)
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})